package spark_from_scratch.basic

import org.apache.spark.mllib.linalg.Matrices

/**
 * @author andrew
 * @email zengjunjie1026@163.com
 * @date 2020/9/3 01:05
 * @version 1.0
 */
object MatrixLearning {
  def main(args: Array[String]) {
    val mx = Matrices.dense(2, 3, Array(1, 2, 3, 4, 5, 6)) //创建一个分布式矩阵
    println(mx) //打印结果

    val arr = (1 to 6).toArray.map(_.toDouble)
    val mx2 = Matrices.dense(2, 3, arr) //创建一个分布式矩阵
    println(mx2) //打印结果

    //    val arr3=(1 to 20).toArray.map(_.toDouble)
    val arr3 = (21 to 40).toArray.map(_.toDouble)
    val mx3 = Matrices.dense(4, 5, arr3) //创建一个分布式矩阵
    println(mx3) //打印结果
//    println(mx3.index(0, 0))
//    println(mx3.index(1, 1))
//    println(mx3.index(2, 2))
    println(mx3.numRows)
    println(mx3.numCols)
    //Find the number of values stored explicitly. These values can be zero as well.
    println(mx3.numActives)
    //非零的元素个数
    println(mx3.numNonzeros)
    //最大值
    //    println(mx3.)
  }
}
